import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/page/uzi_page.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

import 'emergency_page.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: PreferredSize(
            child: AppBar(
              // title:
              title: Row(children: <Widget>[
                SizedBox(
                  width: ScreenUtil().setWidth(150),
                ),
                // Image.network("http://www.beitop.com/bpjs/img/logo.png",width: ScreenUtil().setWidth(48),),
                Image.asset(
                  "images/logo.png",
                  width: ScreenUtil().setWidth(48),
                ),
                SizedBox(
                  width: ScreenUtil().setWidth(10),
                ),
                Text(
                  "北排建设应急管理平台",
                  style: TextStyle(fontSize: ScreenUtil().setSp(32)),
                ),
              ]),
            ),
            preferredSize: Size.fromHeight(ScreenUtil().setHeight(80))),
        body: SingleChildScrollView(
          child: Column(children: <Widget>[
            new Banners(),
//            Container(
//              color: Colors.white,
////              height: ScreenUtil().setHeight(ScreenUtil().setHeight(620)),
//              padding: EdgeInsets.only(top: 20,bottom: 20),
//              child: new ServiceCategories(),
//            ),
           ServiceCategories(),
            SizedBox(
              height: ScreenUtil().setHeight(20),
            ),
            TileBiao(),
            LeiBiaoTu(),
            CheLiang(),
            ServiceCategoriesJueSe(),
          ]),
        ));
  }
}

//首页banner
class Banners extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<String> imagest = new List();
    imagest.add("http://www.beitop.com/bpjs/img/banner2.jpg");
    imagest.add("http://www.beitop.com/bpjs/img/banner1.jpg");
    return Container(
      child: new Container(
          height: ScreenUtil().setHeight(150),
          child: Swiper(
            itemCount: imagest.length,
            autoplay: true,
            //是否自动播放
            autoplayDelay: 3000,
            //item数量
            itemBuilder: (BuildContext context, int index) {
              //item构建
              return new Image.network(
                imagest[index],
                fit: BoxFit.fill,
              );
            },
          )),
    );
  }
}

//列表视图
class ServiceCategories extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<ServiceItemView> serviceItemViews = new List();
    serviceItemViews.add(ServiceItemView(
        icon: "images/home/f1.gif", title: "抢险工程", url: EmergencyPage()));
    serviceItemViews.add(ServiceItemView(
        icon: "images/home/f2.gif", title: "物料管理", url: UziPage()));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f3.gif", title: "库存管理"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f4.gif", title: "车辆档案"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f5.gif", title: "维修管理"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f6.gif", title: "车辆租赁"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f7.gif", title: "年检记录"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/f8.gif", title: "更多"));

    // return GridView.count(
    //   // controller: ,
    //   crossAxisCount: 4,
    //   padding: EdgeInsets.symmetric(vertical: 0),
    //   children: serviceItemViewModels.map((item) => ServiceItem(item)).toList(),
    //  //physics
    // );
    // .physics(
    //   NeverScrollableScrollPhysics:false,
    // );
    return Container(
      color: Colors.white,
        alignment: Alignment.center,
        width: ScreenUtil().setHeight(750),
        height: ScreenUtil().setHeight(260),
//        padding: EdgeInsets.only(left: 20),
        child:
                Wrap(
                    spacing: 40,
                  children:serviceItemViews.map((value){
                    return ServiceItem(value);
                  }).toList(),
                )
//        GridView.builder(
////          padding: EdgeInsets.only(bottom: 30),
//          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
//            // 左右间隔
//            crossAxisSpacing: 0,
//            // 上下间隔
//            mainAxisSpacing: 0,
////            //宽高比
////            childAspectRatio: 2 / 5,
//            crossAxisCount: 4,
//            // mainAxisSpacing:20,
//          ),
////          physics: new NeverScrollableScrollPhysics(),
//
//
//          itemCount: serviceItemViews.length,
//          itemBuilder: (BuildContext context, int index) {
//            return ServiceItem(serviceItemViews[index]);
//          },
//        )
    );
  }
}

class ServiceItem extends StatelessWidget {
  // final ServiceItemViewModel data;
  final ServiceItemView data;

  ServiceItem(this.data);

  @override
  Widget build(BuildContext context) {
    return Container(

      padding: EdgeInsets.only(top: 10),
      child: Column(
        children: <Widget>[
          // Expanded(child: this.data.icon),
          InkWell(
            onTap: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                return data.url;
              }));
            },
            child: Container(
              height:ScreenUtil().setHeight(70),
              child: Image.asset(
                this.data.icon,
                width: ScreenUtil().setWidth(65),
                height: ScreenUtil().setHeight(65),
              ),
            ),
          ),

          Text(
            this.data.title,
            style: TextStyle(
                fontSize: ScreenUtil().setSp(22),
                color: Color(0xFF333333),
                fontFamily: "familyFontStyle"),
          ),
        ],
      ),
    );
  }
}

class TileBiao extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenUtil().setHeight(70),
      padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
      color: Colors.white,
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              "抢险物资管理",
              style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: ScreenUtil().setSp(25),
                  fontFamily: "familyFontStyle",
                  fontWeight: FontWeight.w100),
            ),
            Text(
              "全部分类",
              style: TextStyle(
                  color: Color(0xFFacafbf),
                  fontSize: ScreenUtil().setSp(20),
                  fontFamily: "familyFontStyle"),
            ),
          ]),
    );
  }
}

class ServiceItemView {
  /// 图标
  final String icon;

  /// 标题
  final String title;

  ///跳转地址
  final StatefulWidget url;

  const ServiceItemView({
    this.icon,
    this.title,
    this.url,
  });
}

class LeiBiaoXi extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: new BoxDecoration(
          //背景
          color: Color(0xFFf8f8f8),
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
//        color: Colors.deepOrangeAccent,
        margin: EdgeInsets.only(left: 20),
        padding: EdgeInsets.all(10),
//      width: ScreenUtil().setWidth(100),
        height: ScreenUtil().setHeight(120),
        child: Row(children: <Widget>[
          Column(children: <Widget>[
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "抢险工程",
              style: TextStyle(
                  color: Color(0xFF004ce5),
                  fontSize: ScreenUtil().setSp(25),
                  fontFamily: "familyFontStyle"),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "图表查看",
              style: TextStyle(
                  color: Color(0xFFacafbf), fontSize: ScreenUtil().setSp(20)),
            ),
          ]),
          SizedBox(
            width: ScreenUtil().setWidth(80),
          ),
          Image.asset(
            "images/home/g1.png",
            width: ScreenUtil().setWidth(90),
          ),
        ]));
  }
}

class LeiBiaoXi1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: new BoxDecoration(
          //背景
          color: Color(0xFFf8f8f8),
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
//        color: Colors.deepOrangeAccent,
        margin: EdgeInsets.only(left: 20),
        padding: EdgeInsets.all(10),
//      width: ScreenUtil().setWidth(100),
        height: ScreenUtil().setHeight(120),
        child: Row(children: <Widget>[
          Column(children: <Widget>[
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "工程分析",
              style: TextStyle(
                  color: Color(0xFF004ce5),
                  fontSize: ScreenUtil().setSp(25),
                  fontFamily: "familyFontStyle"),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "图表查看",
              style: TextStyle(
                  color: Color(0xFFacafbf), fontSize: ScreenUtil().setSp(20)),
            ),
          ]),
          SizedBox(
            width: ScreenUtil().setWidth(80),
          ),
          Image.asset(
            "images/home/g2.png",
            width: ScreenUtil().setWidth(90),
          ),
        ]));
  }
}

class LeiBiaoXi2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: new BoxDecoration(
          //背景
          color: Color(0xFFf8f8f8),
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
//        color: Colors.deepOrangeAccent,
        margin: EdgeInsets.only(left: 20),
        padding: EdgeInsets.all(10),
//      width: ScreenUtil().setWidth(100),
        height: ScreenUtil().setHeight(120),
        child: Row(children: <Widget>[
          Column(children: <Widget>[
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "物资统计",
              style: TextStyle(
                  color: Color(0xFF004ce5),
                  fontSize: ScreenUtil().setSp(25),
                  fontFamily: "familyFontStyle"),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "图表查看",
              style: TextStyle(
                  color: Color(0xFFacafbf), fontSize: ScreenUtil().setSp(20)),
            ),
          ]),
          SizedBox(
            width: ScreenUtil().setWidth(80),
          ),
          Image.asset(
            "images/home/g3.png",
            width: ScreenUtil().setWidth(90),
          ),
        ]));
  }
}

class LeiBiaoXi3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: new BoxDecoration(
          //背景
          color: Color(0xFFf8f8f8),
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(5.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
//        color: Colors.deepOrangeAccent,
        margin: EdgeInsets.only(left: 20),
        padding: EdgeInsets.all(10),
//      width: ScreenUtil().setWidth(100),
        height: ScreenUtil().setHeight(120),
        child: Row(children: <Widget>[
          Column(children: <Widget>[
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "物资统计",
              style: TextStyle(
                  color: Color(0xFF004ce5),
                  fontSize: ScreenUtil().setSp(25),
                  fontFamily: "familyFontStyle"),
            ),
            SizedBox(
              height: ScreenUtil().setHeight(5),
            ),
            Text(
              "图表查看",
              style: TextStyle(
                  color: Color(0xFFacafbf), fontSize: ScreenUtil().setSp(20)),
            ),
          ]),
          SizedBox(
            width: ScreenUtil().setWidth(80),
          ),
          Image.asset(
            "images/home/g4.png",
            width: ScreenUtil().setWidth(90),
          ),
        ]));
  }
}

class LeiBiaoTu extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(right: 20, bottom: 10),
      color: Colors.white,
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                child: LeiBiaoXi(),
                flex: 1,
              ),
              Expanded(
                child: LeiBiaoXi1(),
                flex: 1,
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setHeight(30),
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: LeiBiaoXi2(),
                flex: 1,
              ),
              Expanded(
                child: LeiBiaoXi3(),
                flex: 1,
              ),
            ],
          )
        ],
      ),
    );
  }
}

class CheLiang extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: 10, bottom: 10),
      height: ScreenUtil().setHeight(70),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Container(
              padding: EdgeInsets.only(left: 20),
              child: Text(
                "车辆设备管理",
                style: TextStyle(
                    color: Color(0xFF333333),
                    fontSize: ScreenUtil().setSp(25),
                    fontFamily: "familyFontStyle"),
              ),
            ),
            flex: 4,
          ),
          Expanded(
            child: Container(
              child: Text(
                "在库",
                style: TextStyle(
                    color: Color(0xFFccccd6), fontSize: ScreenUtil().setSp(20)),
              ),
            ),
            flex: 1,
          ),
          Expanded(
            child: Container(
              child: Text(
                "在修",
                style: TextStyle(
                    color: Color(0xFFccccd6), fontSize: ScreenUtil().setSp(20)),
              ),
            ),
            flex: 1,
          ),
          Expanded(
            child: Container(
              child: Text(
                "借出",
                style: TextStyle(
                    color: Color(0xFFccccd6), fontSize: ScreenUtil().setSp(20)),
              ),
            ),
            flex: 1,
          ),
          Expanded(
            child: Container(
              child: Text(
                "其他",
                style: TextStyle(
                    color: Color(0xFFccccd6), fontSize: ScreenUtil().setSp(20)),
              ),
            ),
            flex: 1,
          ),
          Expanded(
            child: Container(
              padding: EdgeInsets.only(right: 20),
              child: Text(
                ">",
                textAlign: TextAlign.right,
                style: TextStyle(
                    color: Color(0xFFccccd6),
                    fontSize: ScreenUtil().setSp(35),
                    fontFamily: "familyFontStyle"),
              ),
            ),
            flex: 3,
          ),
        ],
      ),
    );
  }
}

class JueSe extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
//        Expanded(
        ],
      ),
    );
  }
}

class ServiceCategoriesJueSe extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<ServiceItemView> serviceItemViews = new List();
    serviceItemViews.add(ServiceItemView(
        icon: "images/home/m1.png", title: "抢险工程", url: EmergencyPage()));
    serviceItemViews.add(ServiceItemView(
        icon: "images/home/m2.png", title: "物料管理", url: UziPage()));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/m3.png", title: "库存管理"));
    serviceItemViews
        .add(ServiceItemView(icon: "images/home/m4.png", title: "车辆档案"));

    return Container(
        height: ScreenUtil().setHeight(150),
        color: Colors.white,
        padding: EdgeInsets.only(top: 5),
        child: GridView.builder(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
            // mainAxisSpacing:20,
          ),
          physics: new NeverScrollableScrollPhysics(),
          itemCount: serviceItemViews.length,
          itemBuilder: (BuildContext context, int index) {
            return ServiceItem(serviceItemViews[index]);
          },
        ));
  }
}
